package com.zyj.exam_app.configuration;

import com.zyj.exam_app.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {

    @Value("${server.servlet.context-path}")
    private String contextPath;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")  //所有请求都被拦截包括静态资源
                .excludePathPatterns(
                        "/login",
                        "/doLogin",
                        "/resource/css/**",
                        "/resource/js/**",
                        "/resource/img/**",
                        "/resource/fonts/**",
                        "/resource/icon/**",
                        "/resource/images/**"); //放行的请求
        //不需要考虑server.servlet.context-path设置了什么
    }

}
